/*******************************************************************************
 * Copyright (c) 2012, 2013 XML-Print Project.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     XML-Print Project - initial API and implementation
 ******************************************************************************/
package info.xmlprint.core.referencesystem;

import info.xmlprint.run.Constants;

import java.io.Serializable;
import java.util.HashMap;

import org.dom4j.Element;

public class PageMaster extends AbstractBaseItem implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7278616121731114449L;
	
	public PageMaster() {
		init();
	}
	
	public void init() {
		valueMap = new HashMap<String, String>();

		nodeNameMap = new HashMap<String, String>();
		nodeNameMap.put("name", "name");
		nodeNameMap.put("page-layout-width", "page-layout-width");
		nodeNameMap.put("page-layout-height", "page-layout-height");
		nodeNameMap.put("page-layout-margin-bottom", "page-layout-margin-bottom");
		nodeNameMap.put("page-layout-margin-top", "page-layout-margin-top");
		nodeNameMap.put("page-layout-margin-left", "page-layout-margin-left");
		nodeNameMap.put("page-layout-margin-right", "page-layout-margin-right");
		nodeNameMap.put("page-layout-doublesided", "page-layout-doublesided");
		nodeNameMap.put("page-layout-lehead", "page-layout-lehead");
		nodeNameMap.put("page-layout-cehead", "page-layout-cehead");
		nodeNameMap.put("page-layout-rehead", "page-layout-rehead");
		nodeNameMap.put("page-layout-lohead", "page-layout-lohead");
		nodeNameMap.put("page-layout-cohead", "page-layout-cohead");
		nodeNameMap.put("page-layout-rohead", "page-layout-rohead");
		nodeNameMap.put("page-layout-lefoot", "page-layout-lefoot");
		nodeNameMap.put("page-layout-cefoot", "page-layout-cefoot");
		nodeNameMap.put("page-layout-refoot", "page-layout-refoot");
		nodeNameMap.put("page-layout-lofoot", "page-layout-lofoot");
		nodeNameMap.put("page-layout-cofoot", "page-layout-cofoot");
		nodeNameMap.put("page-layout-rofoot", "page-layout-rofoot");

		// set all value="";
		for (String k : nodeNameMap.keySet()) {
			valueMap.put(k, "");
		}
		
		/*valueMap.put("page-layout-width", Constants.A4_W);
		valueMap.put("page-layout-height", Constants.A4_H);
		valueMap.put("page-layout-margin-top", Constants.margin_T);
		valueMap.put("page-layout-margin-bottom", Constants.margin_B);
		valueMap.put("page-layout-margin-left", Constants.margin_L);
		valueMap.put("page-layout-margin-right", Constants.margin_R);
		valueMap.put("page-layout-doublesided", Constants.doublesided.toString());*/
		}

	@Override
	public void setRootElementName() {
		rootElementName = "pagemaster"; //$NON-NLS-1$
	}

	@Override
	public void updateByElement(Element elem) {
		if (elem == null || !elem.getName().equalsIgnoreCase(rootElementName))
			return;
		readNodeValue(elem,
				new String[] { "name", "page-layout-width", "page-layout-height", 
				"page-layout-margin-top", "page-layout-margin-bottom", "page-layout-margin-left",
				"page-layout-margin-right", "page-layout-doublesided", 
				"page-layout-lehead", "page-layout-cehead", "page-layout-rehead",
				"page-layout-lohead", "page-layout-cohead", "page-layout-rohead",
				"page-layout-lefoot", "page-layout-cefoot", "page-layout-refoot",
				"page-layout-lofoot", "page-layout-cofoot", "page-layout-rofoot" });//$NON-NLS-1$
	}
	
	public void setAttribute(String k, String v) {
		if (valueMap.containsKey(k))
			valueMap.put(k, v);
	}
}
